package logger

import (
	"strconv"
)

type FormatterSeparator struct {
	Separator   string
	KVSeparator string
}

func (f *FormatterSeparator) Begin(ctx *Context) {
	//nothing
}

func (f *FormatterSeparator) End(ctx *Context) {
	//nothing
}

func (f *FormatterSeparator) AppendTimeBytes(ctx *Context, bs []byte) {
	ctx.Buffer().Write(bs)
}

func (f *FormatterSeparator) AppendLevel(ctx *Context, lv Level) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(lv.String())
}

func (f *FormatterSeparator) PrefixBegin(ctx *Context) {
	//nothing
}

func (f *FormatterSeparator) PrefixEnd(ctx *Context) {
	//nothing
}

func (f *FormatterSeparator) AppendPrefix(ctx *Context, index int, pre string) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(pre)
}

func (f *FormatterSeparator) FieldBegin(ctx *Context) {
	//nothing
}

func (f *FormatterSeparator) FieldEnd(ctx *Context) {
	//nothing
}

func (f *FormatterSeparator) AppendFieldInt64(ctx *Context, index int, k string, v int64) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(k)
	ctx.Buffer().WriteString(f.KVSeparator)
	bs := strconv.AppendInt(ctx.Buffer().AvailableBuffer(), v, 10)
	ctx.Buffer().Write(bs)
}

func (f *FormatterSeparator) AppendFieldUint64(ctx *Context, index int, k string, v uint64) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(k)
	ctx.Buffer().WriteString(f.KVSeparator)
	bs := strconv.AppendUint(ctx.Buffer().AvailableBuffer(), v, 10)
	ctx.Buffer().Write(bs)
}

func (f *FormatterSeparator) AppendFieldFloat64(ctx *Context, index int, k string, v float64) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(k)
	ctx.Buffer().WriteString(f.KVSeparator)
	bs := strconv.AppendFloat(ctx.Buffer().AvailableBuffer(), v, 'f', -1, 64)
	ctx.Buffer().Write(bs)
}

func (f *FormatterSeparator) AppendFieldString(ctx *Context, index int, k string, v string) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(k)
	ctx.Buffer().WriteString(f.KVSeparator)
	ctx.Buffer().WriteString(v)
}

func (f *FormatterSeparator) AppendMessage(ctx *Context, msg string) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(msg)
}

var FormatterSeparator_ErrorPrefix = "error: "

func (f *FormatterSeparator) AppendError(ctx *Context, err error) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(FormatterSeparator_ErrorPrefix)
	ctx.Buffer().WriteString(err.Error())
}

func (f *FormatterSeparator) AppendCodeLine(ctx *Context, file string, line int) {
	ctx.Buffer().WriteString(f.Separator)
	ctx.Buffer().WriteString(file)
	ctx.Buffer().WriteString(":")
	bs := strconv.AppendInt(ctx.Buffer().AvailableBuffer(), int64(line), 10)
	ctx.Buffer().Write(bs)
}
